package com.fairytask.logic
{
	import com.fairytask.data.Modulator;
	import com.fairytask.event.BattleEvent;
	import com.fairytask.scene.BattleScene;
	
	import starling.events.EventDispatcher;
	import starling.events.TouchEvent;
	import starling.events.TouchPhase;

	/**
	 * 战斗逻辑 
	 * @author game
	 * 
	 */	
	public class BattleLogic extends EventDispatcher
	{
		private static var _instance	:BattleLogic;

		//数据
		private var model			:Modulator;
		private var selectedCells	:Array	=	[];
		//实例化
		private var battleScene	:BattleScene;
		
		public static function get instance():BattleLogic
		{
			if(null==_instance)
			{
				_instance	=	new BattleLogic();
			}
			return _instance;
		}

		
		public function BattleLogic()
		{
			super();
			model	=	Modulator.instance;
			battleScene	=	BattleScene.instance;
			
			initEvent();
		}
		
		private function initEvent():void
		{
			model.addEventListener(BattleEvent.ENTER_BATTLE,onEnter);
			battleScene.addEventListener(TouchEvent.TOUCH,onTouch);
		}
		
		/**
		 * 进入战斗 
		 * @param evt
		 * 
		 */
		private function onEnter(evt:BattleEvent):void
		{
			battleScene.start(evt.battleId);
		}
		
		/**
		 * 鼠标事件 
		 * @param evt
		 * 
		 */
		private function onTouch(evt:TouchEvent):void
		{
			trace("鼠标行为",evt.data[0].phase);
			var cStatus	:String	=	evt.data[0].phase;
			switch(cStatus)
			{
				case TouchPhase.BEGAN:
					onDownExcute();
					break;
			}
		}
		
		/**
		 * 鼠标按下 
		 * 
		 */
		private function onDownExcute():void
		{
			//var selectIdx	:int	=	selectedCells.
		}
	}
}